﻿using System;
using System.Collections.Generic;

namespace AppMain
{
    public class TMHitBackProcesser : BaseMoveProcesser
    {

        float passDistance = 0;
        protected override void onEnter(RoleMove_Status fromStatus)
        {
            passDistance = 0;
            //this.agent.playAnim("hitBack");
            this.agent.Lock((int)Lock_Status.MoveLock);
        }

        protected override void onUpdate()
        {
            passDistance = 0;
        }

        protected override void onExit(RoleMove_Status toStatus)
        {

        }

        protected override void onTick(float frameTime)
        {
            if (passDistance < data.distance)
            {
                float x = data.speed * data.dir.x * frameTime;
                float z = data.speed * data.dir.z * frameTime;
                BaseScene scene = this.agent.AttrMap.getAttr<BaseScene>(RoleAttr.Scene).Value;
                Vec2 result = Physics.moveCast(this.agent.box3D, scene.colliderSegments, x, z);
                float xDistance = result.x;
                float zDistance = result.y;
                this.agent.move(xDistance, zDistance);
                passDistance += Math.Abs(x);
                passDistance += Math.Abs(z);
            }

            if (passDistance >= data.distance && this.timeIsArrive)
            {
                this.agent.moveWidget.doMove(new MoveData() { moveStatus = Move_Status.SelfStand });
            }
        }

        protected override void onDispose()
        {

        }

    }
}
